<%-- 
    Document   : giohang_donhang
    Created on : Dec 26, 2013, 5:26:59 PM
    Author     : home
--%>

<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page isErrorPage="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt"  prefix="fmt" %>

<t:layout>
    <jsp:body>
        <c:set var="promotion_start" value="${(ngayHienTai >= khuyenMai.getNgayBatDau()) && (ngayHienTai <= khuyenMai.getNgayKetThuc()) && (khuyenMai.getTinhTrangKhuyenMai() == 1)}" ></c:set>
            <script language="javascript">
                function UpdateCart()
                {
                    document.updatecartForm.submit();
                }
            </script>
            <!-- if $order == 0}/cart/update else /cart/view/order/submit -->
            <form name="updatecartForm" method="POST" action="<c:url value="/GioHang/HoaDon/HoanTat/" />">
            <table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                    <td class="bgtitle">
                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
                            <tr>
                                <td width="20"><img src="<c:url value="/resources/images/" />mui_ten.gif" /></td>
                                <td valign="bottom" class="title">Giỏ hàng</td>
                                <td width="10" valign="bottom">&nbsp;</td>
                            </tr>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td valign="top" ><img src="..<c:url value="/resources/images/" />space.gif" width="1" height="10" /></td>
                </tr>
            </table>
            <br />
            <c:if test="${count_session > 0}">
                <!-- Mới thêm -->
                <table width="98%" border="0" cellspacing="0" cellpadding="2" align="center">
                    <tbody>
                        <tr>
                            <td width="50%">
                                <strong>Mã đơn hàng: 
                                    <input type="hidden" value="MPC${order_code}${checkSession.getMaNd()}" name="order_code" id="order_code">
                                    <font color="#FF0000">MPC${order_code}${checkSession.getMaNd()}</font>
                                </strong>
                            </td>
                            <td>
                                <strong>Ngày đặt hàng:</strong> 
                                <font color="#FF0000">
                                <input type="hidden" value="${order_date.time}" name="order_date" id="order_date">
                                <strong>
                                    <fmt:formatDate value="${order_date}" pattern="dd/MM/yyyy | HH:mm:ss"/>
                                </strong>
                                </font>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <table width="98%" border="0" cellspacing="0" cellpadding="0" align="center">
                    <tbody>
                        <tr>
                            <td valign="top" width="50%">
                                <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
                                    <tbody>
                                        <tr>
                                            <td height="30">
                                                <strong>Thông tin đặt hàng:</strong>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
                                                    <tbody>
                                                        <tr>
                                                            <td width="25%" valign="top">Tên đầy đủ:&nbsp;</td>
                                                            <td valign="top">${checkSession.getHoTen()}</td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top">Điện thoại:&nbsp;</td>
                                                            <td valign="top">${checkSession.getSoDienThoai()}</td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top">Địa chỉ email:&nbsp;&nbsp;</td>
                                                            <td valign="top">${checkSession.getEmail()}</td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top">Địa chỉ:&nbsp;&nbsp;</td>
                                                            <td valign="top">${checkSession.getDiaChi()}<!--, $order_state --></td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                            <td valign="top">
                                <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
                                    <tbody>
                                        <tr>
                                            <td height="30">
                                                <strong>Thông tin giao hàng:</strong>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                <table width="100%" border="0" cellspacing="0" cellpadding="2" align="center">
                                                    <tbody>
                                                        <tr>
                                                            <td width="25%" valign="top">Tên đầy đủ:&nbsp;</td>
                                                            <td><input name="order_name" type="hidden" id="order_name" value="${order_name}" />
                                                                ${order_name}
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top">Điện thoại:&nbsp;</td>
                                                            <td>
                                                                <input name="order_phone" type="hidden" id="order_phone" value="${order_phone}" />
                                                                ${order_phone}
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top">Địa chỉ email:&nbsp;&nbsp;</td>
                                                            <td>
                                                                <input name="order_email" type="hidden" id="order_email" value="${order_email}" />
                                                                ${order_email}
                                                            </td>
                                                        </tr>
                                                        <tr>
                                                            <td valign="top">Địa chỉ nhận:&nbsp;&nbsp;</td>
                                                            <td>
                                                                <input name="order_address" type="hidden" id="order_address" value="${order_address}" />
                                                                ${order_address}
                                                            </td>
                                                        </tr>
                                                    </tbody>
                                                </table>
                                            </td>
                                        </tr>
                                    </tbody>
                                </table>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <table width="98%" border="0" cellspacing="0" cellpadding="2" align="center">
                    <tbody>
                        <tr>
                            <td height="30">
                                <strong>Phương thức thanh toán: </strong>
                                <font color="#FF0000">
                                <c:if test="${phuongthucthanhtoan == 1}">
                                    <strong>Thanh toán tiền mặt khi giao hàng tận nơi</strong>
                                </c:if>
                                <c:if test="${phuongthucthanhtoan == 2}">
                                    <strong>Thanh toán chuyển khoản NganLuong</strong>
                                </c:if>
                                <input type="hidden" value="${phuongthucthanhtoan}" name="phuongthucthanhtoan" id="phuongthucthanhtoan">
                                </font>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <strong> Yêu cầu khác: </strong>
                                <input name="order_note" type="hidden" id="order_note" value="${order_note}" />
                                ${order_note}
                            </td>
                        </tr>
                    </tbody>
                </table>
                <br>
                <!-- End - Mới thêm -->

                <table width='98%' align='center' border='0' cellpadding='2' cellspacing='0' bordercolor='#CCCCCC' style='border-collapse:collapse'>
                    <tr>
                        <td class='bgmenupro border3' height='30' bgcolor='#DDDDDD' width='5%'>
                            <div align='center'>
                                <strong>STT</strong>
                            </div>
                        </td>
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='10%'>
                            <div align='center'>
                                <strong>Hình ảnh</strong>
                            </div>
                        </td><td class='bgmenupro border3' bgcolor='#DDDDDD'>
                            <div align='center'>
                                <strong>Tên sản phẩm</strong>
                            </div>
                        </td>
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='18%'>
                            <div align='center'>
                                <strong>Giá tiền</strong>
                            </div>
                        </td>
                        <td class='bgmenupro border3' bgcolor='#DDDDDD' width='10%'>
                            <div align='center'>
                                <strong>Số lượng</strong>
                            </div>
                        </td>
                        <td class='bgmenupro borderfull' bgcolor='#DDDDDD' width='18%'>
                            <div align='center'>
                                <strong>Thành tiền</strong>
                            </div>
                        </td>
                    </tr>
                    <!-- sản phẩm mua -->
                    <c:set var="tongDonGia" value="0" />
                    <c:forEach var="sanPham" varStatus="sanPhamCounter" items="${listSanPhamGioHang}">
                        <tr>
                            <td class='fontsizecart border3'>
                                <div align='center'>${sanPhamCounter.count}</div>
                            </td>
                            <td class='border3' >
                                <div align='center'>
                                    <a href='<c:url value="/ChiTietSanPham/${sanPham.getMaSp()}" />'>
                                        <img src='<c:url value="/resources/images/" />product/${sanPham.getHinh()}' width='60' border='0'>
                                    </a>
                                </div>
                            </td>
                            <td class='fontsizecart border3'>
                                <div align='center'>
                                    <a href='<c:url value="/ChiTietSanPham/${sanPham.getMaSp()}" />' class='linkcart'>${sanPham.getTenSanPham()}</a>
                                </div>
                            </td>
                            <td class='cartprice fontsizecart borderfull'>
                                <c:if test="${promotion_start == true}" >
                                    <fmt:formatNumber type="number" value="${sanPham.getDonGia()*(100-khuyenMai.getPhanTram())/100}" /> VNĐ 
                                </c:if>
                                <c:if test="${promotion_start == false}" >
                                    <fmt:formatNumber type="number" value="${sanPham.getDonGia()}" /> VNĐ
                                </c:if>

                            </td>
                            <td class='border3'>
                                <div align='center'>
                                    ${sanPham.getSoLuong()}
                                </div>
                            </td>
                            <td class='borderfull' style="text-align: center">
                                <strong>
                                    <c:if test="${promotion_start == true}" >
                                        <c:set var="tongDonGia" value="${tongDonGia + (sanPham.getDonGia()*(100-khuyenMai.getPhanTram())/100)*sanPham.getSoLuong()}" />
                                        <fmt:formatNumber type="number" value="${(sanPham.getDonGia()*(100-khuyenMai.getPhanTram())/100)*sanPham.getSoLuong()}" /> VNĐ 
                                    </c:if>
                                    <c:if test="${promotion_start == false}" >
                                        <c:set var="tongDonGia" value="${tongDonGia + sanPham.getDonGia()*sanPham.getSoLuong()}" />
                                        <fmt:formatNumber type="number" value="${sanPham.getDonGia()*sanPham.getSoLuong()}" /> VNĐ
                                    </c:if>
                                </strong>
                            </td>
                        </tr>
                    </c:forEach>
                    <!-- // sản phẩm mua -->
                    <tr>
                        <td colspan='5' class='cartprice fontred fontsizecart border3' >
                            <strong>Tổng giá trị</strong>
                        </td>
                        <td class='cartprice fontred fontsizecart borderfull' ><fmt:formatNumber type="number" value="${tongDonGia}" /> VNĐ</td>
                    <input type="hidden" value="${tongDonGia}" name="order_total" id="order_total">
                    </tr>
                </table>
                <br>
                <!-- Moi them -->
                <input type="hidden" value="${promotion_start}" name="promotion_start" id="promotion_start">
                <table border="0" align="center" cellpadding="5" cellspacing="0">
                    <tbody>
                        <tr>
                            <td>
                                <c:if test="${phuongthucthanhtoan == 1}">
                                    <input type="image" src="<c:url value="/resources/images/" />btn_pay.gif" name="order_pay" onclick="return gotoSubmit()">
                                </c:if>
                                <c:if test="${phuongthucthanhtoan == 2}">
                                    <a target="_blank" href="https://www.nganluong.vn/button_payment.php?receiver=tranquocminh1112@gmail.com&product_name=MPC${order_code}${checkSession.getMaNd()}&price=${tongDonGia/1000}&return_url=http://localhost:8084/MayAnhKTS/GioHang/HoaDon/ThanhCong&comments=Thanh toán đơn hàng của {$order_name}." >
                                        <img src="https://www.nganluong.vn/data/images/buttons/3.gif"  border="0" />
                                    </a> 
                                </c:if>
                            </td>
                        </tr>
                    </tbody>
                </table>
                <!-- End - Moi them -->
            </c:if>
            <c:if test="${count_session == 0}">
                <div align="center">
                    Quý khách vui lòng chọn <a href="<c:url value="/SanPham/" />"><u>sản phẩm</u></a> để mua.
                </div>
            </c:if>
        </form>
        <br />
    </jsp:body>
</t:layout>